home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / land.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  3KB  |  175 lines

  1. /* -------------------------------- land.c ---------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Look after the landscape. These objects do not move or get simulated!
  8. */
  9.  
  10. #include "fly.h"
  11.  
  12.  
  13. #define RANGE    20
  14.  
  15. extern int FAR
  16. land_init (void)
  17. {
  18.     BODY    *b;
  19.  
  20.     CL = CLT = 0;
  21.  
  22.     if (!create_land (O_GROUND)        /* must be first! */
  23.         || !create_land (O_LOW))        /* must be second! */
  24.         return (1);
  25.  
  26.     if (lnd_read () < 0)
  27.         return (1);
  28.  
  29.     if (!(st.flags&SF_LANDSCAPE))
  30.         return (0);
  31.  
  32.     b = bodies_new (-1);
  33.     if (!b)
  34.         return (1);
  35.     b->init = paddoc_init;
  36.     if ((*b->init) (b)) {
  37.         bodies_del (b->name);
  38.         return (1);
  39.     }
  40.  
  41.     st.landx = 30000;        /* force landscaping */
  42.     st.landy = 30000;
  43.  
  44.     return (0);
  45. }
  46.  
  47. extern void FAR
  48. land_term (void)
  49. {
  50.     list_clear (&CL);
  51. }
  52.  
  53. LOCAL_FUNC int NEAR
  54. land_add (ONAME lname, int nx, int ny)
  55. {
  56.     OBJECT    *p;
  57.     int    control;
  58.  
  59.     Fsrand (nx);
  60.     Fsrand (ny ^ Frand ());
  61.     control = Frand () % 512;
  62.  
  63.     if (control > 3)
  64.         return (0);
  65.  
  66.     if (T(p = create_land (lname))) {
  67.         p->flags |= F_LAND;
  68.         p->R[X] = nx * 1000L * VONE;
  69.         p->R[Y] = ny * 1000L * VONE;
  70.         if (control)        /* paddoc */
  71.             p->R[Z] = 0;
  72.         else {            /* cloud */
  73.             p->R[Z] = (Frand() % 2000 + 2000)*(long)VONE;
  74.             p->color = CC_WHITE;
  75.         }
  76.     }
  77.  
  78.     return (0);
  79. }
  80.  
  81. extern int FAR
  82. land_update (OBJECT *pov)
  83. {
  84.     long    minx, miny, maxx, maxy;
  85.     int    x, y, xl, xh, yl, yh, xxl, xxh, xx, yy;
  86.     OBJECT    *p, *prev;
  87.     ONAME    lname;
  88.  
  89.     if (F(p = CL) || O_GROUND != p->name) {
  90.         MsgPrintf (-100, "Missing GROUND object!");
  91.         return (1);
  92.     }
  93.     st.bodies[p->name]->dynamics (p, st.interval);
  94.  
  95.     if (F(p = p->next) || O_LOW != p->name) {
  96.         MsgPrintf (-100, "Missing LOW object!");
  97.         return (1);
  98.     }
  99.     st.bodies[p->name]->dynamics (p, st.interval);
  100.  
  101.     if (!(st.flags&SF_LANDSCAPE))
  102.         return (0);
  103.  
  104.     x = (int)(pov->R[X] / VONE / 1000);        /* get square */
  105.     y = (int)(pov->R[Y] / VONE / 1000);
  106.  
  107.     if (x == st.landx && y == st.landy)
  108.         return (0);
  109.  
  110.     minx = (x-RANGE)*1000L*VONE;
  111.     maxx = (x+RANGE)*1000L*VONE;
  112.     miny = (y-RANGE)*1000L*VONE;
  113.     maxy = (y+RANGE)*1000L*VONE;
  114.     for (prev = 0, p = CL; p;) {            /* delete old */
  115.         if ((p->flags & F_LAND) &&
  116.             (p->R[X] < minx || p->R[X] > maxx || 
  117.              p->R[Y] < miny || p->R[Y] > maxy))
  118.                 p = delete_land (p);
  119.         else
  120.             p = p->next;
  121.     }
  122.  
  123.     if (st.landx < x) {
  124.         xxl = x-RANGE;
  125.         xh  = x+RANGE;
  126.         xxh = st.landx+RANGE;
  127.         xl  = xxh+1;
  128.         if (xl < xxl)
  129.             xl = xxl;
  130.     } else {
  131.         xl  = x-RANGE;
  132.         xxh = x+RANGE;
  133.         xxl = st.landx-RANGE;
  134.         xh  = xxl-1;
  135.         if (xh > xxh)
  136.             xh = xxh;
  137.     }
  138.  
  139.     if (st.landy < y) {
  140.         yh = y+RANGE;
  141.         yl = st.landy+RANGE+1;
  142.         if (yl < y-RANGE)
  143.             yl = y-RANGE;
  144.     } else {
  145.         yl = y-RANGE;
  146.         yh = st.landy-RANGE-1;
  147.         if (yh > y+RANGE)
  148.             yh = y+RANGE;
  149.     }
  150.  
  151.     st.landx = x;
  152.     st.landy = y;
  153.  
  154.     if (-1 == (lname = body_name ("PADDOC")))
  155.         return (1);
  156.  
  157.     for (xx = xl; xx <= xh; ++xx) {
  158.         for (yy = y-RANGE; yy <= y+RANGE; ++yy) {
  159.             if (land_add (lname, xx, yy))
  160.                 return (0);
  161.         }
  162.     }
  163.  
  164.     for (xx = xxl; xx <= xxh; ++xx) {
  165.         for (yy = yl; yy <= yh; ++yy) {
  166.             if (land_add (lname, xx, yy))
  167.                 return (0);
  168.         }
  169.     }
  170.  
  171.     return (0);
  172. }
  173.  
  174. #undef RANGE
  175.